package com.system.commonutils.bean;


import java.io.Serializable;

/**
 * 同一返回数据格式
 */
public class ResponseBean implements Serializable {
    /**
     * 异常码
     */
    private Integer code;

    /**
     * 描述
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    public ResponseBean() {
    }

    public ResponseBean(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseBean(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public ResponseBean(ResponseEnum responseEnum) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    public ResponseBean(ResponseEnum responseEnum, Object data) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
        this.data = data;
    }

    public static ResponseBean success(){
        return new ResponseBean(ResponseEnum.SUCCESS);
    }

    public static ResponseBean success(Object data){
        return new ResponseBean(ResponseEnum.SUCCESS, data);
    }

    public static ResponseBean success(int code, String msg){
        return new ResponseBean(code, msg);
    }

    public static ResponseBean error(int code, String msg){
        return new ResponseBean(code,msg);
    }

    public static ResponseBean error(ResponseEnum responseEnum){
        return new ResponseBean(responseEnum);
    }

    public static ResponseBean error(ResponseEnum responseEnum, Object data){
        return new ResponseBean(responseEnum, data);
    }
    public static ResponseBean errorParams(String msg){
        return new ResponseBean(ResponseEnum.INCORRECT_PARAMS.getCode(), msg);
    }

    public static ResponseBean result(boolean isSuccess, String succMsg, String errMsg){
        if(isSuccess){
            return new ResponseBean(200,succMsg);
        }else {
            return new ResponseBean(500,errMsg);
        }
    }




    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
